package neo4j.learn.Repository.dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class SessionUtils {
	/**
	 * 打开Session
	 * 
	 * @param sessionFactory
	 * @return
	 */
	public static Session openSession(SessionFactory sessionFactory) {
		if (sessionFactory != null) {
			return sessionFactory.openSession();
		}
		System.out.println("sessionFactory为空");
		return null;
	}

	/**
	 * 关闭Session
	 * 
	 * @param session
	 */
	public static void CloseSession(Session session) {
		if (session != null && (session.isConnected() || session.isOpen()))
			session.close();
	}

	/**
	 * 检查Session对象是否为空，为空则返回true，反之为false
	 * 
	 * @param session
	 * @return
	 */
	public static boolean isSessionNull(Session session) {
		if (session == null) {
			return true;
		}

		return false;
	}
}
